<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>部门信息列表</title>
<%@ include file="/common/header/meta.jsp"%>
<%@ include file="/common/header/script.jsp"%>
<script type="text/javascript">
var $dg, params={"categoryId": "${id}"};
	$(function() {
		$dg = $("#dg").datagrid({
			url: $.webapp.root+"/admin/system/deptinfo_item/view_datagrid.do",
			title: '部门信息列表', 
			idField: 'id', fit: true, border: false, pageSize: 30, pageList: [30,40,50,100,200], rownumbers: true,
			remoteSort: false, toolbar: '#toolbars', striped:true, pagination: true, singleSelect: false,
			sortName: 'created', sortOrder: 'desc', queryParams: params,
			frozenColumns: [[
 			    { field: 'ck', checkbox: true },
 			    { field: 'id', title: 'ID', width: 80, hidden: true }
 			]],
 			columns: [[
 			    { field: 'subject', title: '标题', width: 350, tooltip: true, formatter: function(value, row, index){
			    	var open = $.string.format("<p><a href='#' onclick='javascript:open_(\"{0}\")'>{1}</a></p>", row.id, value) ;
			    	return open ;
			    } },
			    { field: 'categoryName', title: '类别', width: 120, align: 'center' },
			    { field: 'deptName', title: '部门', width: 120, align: 'center' },
			    { field: 'operator', title: '操作', width: 120, tooltip: true, formatter: function(value, row, index){
			    	if(row.personId == "${USER_SESSION.user.emp_id}") {
				    	var str = $.string.format("<a href='#' onclick='javascript:edit(\"{0}\")'>修改</a>&nbsp;&nbsp;&nbsp;", row.id) ;
				    	str += $.string.format("<a href='#' onclick='javascript:del(\"{0}\")'>删除</a>", row.id) ; 
				    	return str ;
			    	} else {
			    		return "" ;
			    	}
			    } },
 			    { field: 'created', title: '创建时间', width: 140 },
 			    { field: 'createName', title: '创建者', width: 140 },
 			    { field: 'modifyDate', title: '最后修改时间', width: 140 },
 			    { field: 'modifyName', title: '修改者', width: 140 },
 			]],
			onLoadSuccess: function(node, data) {
				$.fn.datagrid.extensions.onLoadSuccess.apply(this, arguments);
				$dg.datagrid('unselectAll');$dg.datagrid('clearSelections');$dg.datagrid('unselectAll');
			}
		}) ;
	});
	
	
	/* function form_edit(form) {
		var form_url = $.webapp.root+"/admin/system/deptinfo_item/deptinfo_item_add_UI.do?categoryId=${id}" ;
		if("E" == form) {
			var node = $dg.datagrid('getSelected');
			if (node) {
				if(node.personId != "${USER_SESSION.user.emp_id}") {
					alertify.warning("只能修改自己上传的记录！"); return ;
				}
				form_url = $.webapp.root+"/admin/system/deptinfo_item/deptinfo_m_item_form_UI.do?categoryId=${id}&id="+node.id ;
			} else {
				alertify.warning("请选择一条记录！"); return ;
			}
		}
		var $d = $.easyui.showDialog({
			href: form_url, title: "表单", iniframe: false, topMost: true,
			width: 950, height: 700, maximizable: true,
            enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
            buttons : [ 
              { text : '保存并继续', iconCls : 'icon-standard-disk', handler : function() { $.easyui.parent.submitForm($d, $dg, true) ; } },
              { text : '确定', iconCls : 'ext_save', handler : function() { $.easyui.parent.submitForm($d, $dg) ; } },
              { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	} */
	
	function form_edit(form) {
		var form_url = $.webapp.root+"/admin/system/deptinfo_item/deptinfo_item_add_UI.do?categoryId=${id}" ;
		var $d = $.easyui.showDialog({
			href: form_url, title: "表单", iniframe: false, topMost: true,
			width: 950, height: 700, maximizable: true,
            enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
            buttons : [ 
              { text : '保存并继续', iconCls : 'icon-standard-disk', handler : function() { $.easyui.parent.submitForm($d, $dg, true) ; } },
              { text : '确定', iconCls : 'ext_save', handler : function() { $.easyui.parent.submitForm($d, $dg) ; } },
              { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function edit(id) {
		var form_url = $.webapp.root+"/admin/system/deptinfo_item/deptinfo_item_update_UI.do?id="+id ;
		var $d = $.easyui.showDialog({
			href: form_url, title: "表单", iniframe: false, topMost: true,
			width: 950, height: 700, maximizable: true,
            enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
            buttons : [ 
              { text : '保存并继续', iconCls : 'icon-standard-disk', handler : function() { $.easyui.parent.submitForm($d, $dg, true) ; } },
              { text : '确定', iconCls : 'ext_save', handler : function() { $.easyui.parent.submitForm($d, $dg) ; } },
              { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function del(id) {
		$.messager.confirm("您确定要进行该操作？", function (c) { 
			if(c) {
				$.easyui.loading({ msg: "数据删除中，请稍等..."});
				$.post($.webapp.root+"/admin/system/deptinfo_item/delete.do", {"ids" : id}, function(result) {
					if (result.status) {
						$dg.datagrid('unselectAll');$dg.datagrid('reload') ;
						alertify.success(result.msg);
						$.easyui.loaded();
					} else {
						alertify.warning(result.msg);
						$.easyui.loaded();
					}
				}, 'json').error(function() { $.easyui.loaded(); });
			}
		});
	}
	
	//打开详细信息
	function open_(id) {
		$.webapp.open($.webapp.root + "/admin/system/deptinfo_item/deptinfo_open_UI.do?id="+id) ;
	}
	
	function doSearch(value,name){
		params[name] = value
		$dg.datagrid("load",params);
	}
	function searchBox() {
		var search_form = $("#searchForm").form("getData") ;
		params["subject"] = search_form.subject ;
		$dg.datagrid("load",params);
	}
	function searchClear() {
		$("#searchForm").form("clear") ;
		params={"categoryId": "${id}"};
		$dg.datagrid("load",params);
	}
	
</script>
</head>

<body>

	<div id="dg">
		<div id="toolbars">
            <a onClick="form_edit('A');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_add'">添加</a>
            <!-- <a onClick="form_edit('E');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_edit'">编辑</a> -->
            <a onclick="$dg.datagrid('reload');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_reload'">刷新</a>
            <div id="search_bar">
            	<form id="searchForm">
	            	<div class="s_box">
	            		<div class="gr">
		            		<div class="si">
			            		<input class="easyui-searchbox" data-options="searcher:doSearch,width: 250, height: 25, menu: '#topSearchboxMenu'" />
								<div id="topSearchboxMenu" style="width: 200px;">
									<div data-options="name:'subject', iconCls: 'icon-hamburg-zoom'">标题</div>
								</div>
		            		</div>
	            		</div>
						<div class="gr">
		            		<div class="st">
			            		<a onClick="searchBox();" class="easyui-linkbutton" data-options="plain: true, iconCls: 'icon-standard-zoom'">查询</a>
			            		<a onClick="searchClear();" class="easyui-linkbutton" data-options="plain: true, iconCls: 'icon-standard-zoom-out'">重置</a>
		            		</div>
	            		</div>
	            	</div>
            	</form>
            </div>
        </div>
	</div>
	

</body>
</html>